home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / lisp / texinfo.el < prev    next >
Lisp/Scheme  |  1993-07-23  |  29KB  |  746 lines

  1. ;;;; texinfo.el--major mode for editing Texinfo files.
  2. ;; Copyright (C) 1985, '88, '89, 
  3. ;;                '90, '91, '92, '93 Free Software Foundation, Inc.
  4.  
  5. ;;; Author: Robert J. Chassell          
  6. ;;; Maintainer: FSF
  7.  
  8. ;;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24.  
  25. ;;; Autoloads:
  26.  
  27. (autoload 'makeinfo-region
  28.           "makeinfo"
  29.   "Make Info file from region of current Texinfo file, and switch to it.
  30.  
  31. This command does not offer the `next-error' feature since it would
  32. apply to a temporary file, not the original; use the `makeinfo-buffer'
  33. command to gain use of `next-error'."
  34.           t nil)
  35.  
  36. (autoload 'makeinfo-buffer
  37.           "makeinfo"
  38.   "Make Info file from current buffer.
  39.  
  40. Use the \\[next-error] command to move to the next error 
  41. \(if there are errors\)."
  42.           t nil)
  43.  
  44. (autoload 'kill-compilation
  45.           "compile"
  46.   "Kill the process made by the \\[compile] command."
  47.           t nil)
  48.  
  49. (autoload 'makeinfo-recenter-compilation-buffer
  50.           "makeinfo"
  51.   "Redisplay `*compilation*' buffer so most recent output can be seen.
  52. The last line of the buffer is displayed on
  53. line LINE of the window, or centered if LINE is nil."
  54.           t nil)
  55.  
  56. (autoload 'texinfo-make-menu
  57.           "texnfo-upd"
  58.   "Without any prefix argument, make or update a menu.
  59. Make the menu for the section enclosing the node found following point.
  60.  
  61. Non-nil argument (prefix, if interactive) means make or update menus
  62. for nodes within or part of the marked region.
  63.  
  64. Whenever a menu exists, and is being updated, the descriptions that
  65. are associated with node names in the pre-existing menu are
  66. incorporated into the new menu.  Otherwise, the nodes' section titles
  67. are inserted as descriptions."
  68.           t nil)
  69.  
  70. (autoload 'texinfo-all-menus-update
  71.           "texnfo-upd"
  72.   "Update every regular menu in a Texinfo file.
  73. Remove pre-existing master menu, if there is one.
  74.  
  75. If called with a non-nil argument, this function first updates all the
  76. nodes in the buffer before updating the menus."
  77.           t nil)
  78.  
  79. (autoload 'texinfo-master-menu
  80.           "texnfo-upd"
  81.   "Make a master menu for a whole Texinfo file.
  82. Non-nil argument (prefix, if interactive) means first update all
  83. existing nodes and menus.  Remove pre-existing master menu, if there is one.
  84.  
  85. This function creates a master menu that follows the top node.  The
  86. master menu includes every entry from all the other menus.  It
  87. replaces any existing ordinary menu that follows the top node.
  88.  
  89. If called with a non-nil argument, this function first updates all the
  90. menus in the buffer (incorporating descriptions from pre-existing
  91. menus) before it constructs the master menu.
  92.  
  93. The function removes the detailed part of an already existing master
  94. menu.  This action depends on the pre-exisitng master menu using the
  95. standard `texinfo-master-menu-header'.
  96.  
  97. The master menu has the following format, which is adapted from the
  98. recommendation in the Texinfo Manual:
  99.  
  100.    * The first part contains the major nodes in the Texinfo file: the
  101.      nodes for the chapters, chapter-like sections, and the major
  102.      appendices.  This includes the indices, so long as they are in
  103.      chapter-like sections, such as unnumbered sections.
  104.  
  105.    * The second and subsequent parts contain a listing of the other,
  106.      lower level menus, in order.  This way, an inquirer can go
  107.      directly to a particular node if he or she is searching for
  108.      specific information.
  109.  
  110. Each of the menus in the detailed node listing is introduced by the
  111. title of the section containing the menu."
  112.           t nil)
  113.  
  114. (autoload 'texinfo-indent-menu-description
  115.           "texnfo-upd"
  116.   "Indent every description in menu following point to COLUMN.  
  117. Non-nil argument (prefix, if interactive) means indent every
  118. description in every menu in the region.  Does not indent second and
  119. subsequent lines of a multi-line description."
  120.           t nil)
  121.  
  122. (autoload 'texinfo-insert-node-lines
  123.           "texnfo-upd"
  124.   "Insert missing `@node' lines in region of Texinfo file.
  125. Non-nil argument (prefix, if interactive) means also to insert the
  126. section titles as node names; and also to insert the section titles as
  127. node names in pre-existing @node lines that lack names."
  128.           t nil)
  129.  
  130. (autoload 'texinfo-start-menu-description
  131.           "texnfo-upd"
  132.   "In this menu entry, insert the node's section title as a description. 
  133. Position point at beginning of description ready for editing.
  134. Do not insert a title if the line contains an existing description.
  135.  
  136. You will need to edit the inserted text since a useful description
  137. complements the node name rather than repeats it as a title does."
  138.           t nil)
  139.  
  140. (autoload 'texinfo-multiple-files-update
  141.           "texnfo-upd"
  142.   "Update first node pointers in each file included in OUTER-FILE;
  143. create or update main menu in the outer file that refers to such nodes. 
  144. This does not create or update menus or pointers within the included files.
  145.  
  146. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  147. insert a master menu in OUTER-FILE.  This does not create or update
  148. menus or pointers within the included files.
  149.  
  150. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  151. interactive), update all the menus and all the `Next', `Previous', and
  152. `Up' pointers of all the files included in OUTER-FILE before inserting
  153. a master menu in OUTER-FILE.
  154.  
  155. The command also updates the `Top' level node pointers of OUTER-FILE.
  156.  
  157. Notes: 
  158.  
  159.   * this command does NOT save any files--you must save the
  160.     outer file and any modified, included files.
  161.  
  162.   * except for the `Top' node, this command does NOT handle any
  163.     pre-existing nodes in the outer file; hence, indices must be
  164.     enclosed in an included file.
  165.  
  166. Requirements:
  167.  
  168.   * each of the included files must contain exactly one highest
  169.     hierarchical level node, 
  170.   * this highest node must be the first node in the included file,
  171.   * each highest hierarchical level node must be of the same type.
  172.  
  173. Thus, normally, each included file contains one, and only one,
  174. chapter."
  175.           t nil)
  176.  
  177.  
  178. ;;; Code:
  179.  
  180. ;;; Don't you dare insert any `require' calls at top level in this file--rms.
  181.  
  182. ;;; Syntax table
  183.  
  184. (defvar texinfo-mode-syntax-table nil)
  185.  
  186. (if texinfo-mode-syntax-table
  187.     nil
  188.   (setq texinfo-mode-syntax-table (make-syntax-table))
  189.   (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
  190.   (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
  191.   (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
  192.   (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
  193.   (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
  194.   (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
  195.   (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
  196.   (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
  197.   (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
  198.  
  199.  
  200. ;;; Keybindings
  201. (defvar texinfo-mode-map nil)
  202.  
  203. ;;; Keys common both to Texinfo mode and to TeX shell.
  204.  
  205. (defun texinfo-define-common-keys (keymap)
  206.   "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
  207.   (define-key keymap "\C-c\C-t\C-k"    'tex-kill-job)
  208.   (define-key keymap "\C-c\C-t\C-x"    'texinfo-quit-job)
  209.   (define-key keymap "\C-c\C-t\C-l"    'tex-recenter-output-buffer)
  210.   (define-key keymap "\C-c\C-t\C-d"    'texinfo-delete-from-print-queue)
  211.   (define-key keymap "\C-c\C-t\C-q"    'tex-show-print-queue)
  212.   (define-key keymap "\C-c\C-t\C-p"    'texinfo-tex-print)
  213.   (define-key keymap "\C-c\C-t\C-i"    'texinfo-texindex)
  214.  
  215.   (define-key keymap "\C-c\C-t\C-r"    'texinfo-tex-region)
  216.   (define-key keymap "\C-c\C-t\C-b"    'texinfo-tex-buffer))
  217.  
  218. ;; Mode documentation displays commands in reverse order 
  219. ;; from how they are listed in the texinfo-mode-map.
  220.  
  221. (if texinfo-mode-map
  222.     nil
  223.   (setq texinfo-mode-map (make-sparse-keymap))
  224.  
  225.   ;; bindings for `texnfo-tex.el'
  226.   (texinfo-define-common-keys texinfo-mode-map)
  227.  
  228.   ;; bindings for `makeinfo.el'
  229.   (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
  230.   (define-key texinfo-mode-map "\C-c\C-m\C-l" 
  231.     'makeinfo-recenter-compilation-buffer)
  232.   (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
  233.   (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
  234.  
  235.   ;; bindings for updating nodes and menus
  236.  
  237.   (define-key texinfo-mode-map "\C-c\C-um"   'texinfo-master-menu)
  238.  
  239.   (define-key texinfo-mode-map "\C-c\C-u\C-m"   'texinfo-make-menu)
  240.   (define-key texinfo-mode-map "\C-c\C-u\C-n"   'texinfo-update-node)
  241.   (define-key texinfo-mode-map "\C-c\C-u\C-e"   'texinfo-every-node-update)
  242.   (define-key texinfo-mode-map "\C-c\C-u\C-a"   'texinfo-all-menus-update)
  243.  
  244.   (define-key texinfo-mode-map "\C-c\C-s"     'texinfo-show-structure)
  245.  
  246.   (define-key texinfo-mode-map "\C-c}"        'up-list)
  247.   (define-key texinfo-mode-map "\C-c]"        'up-list)
  248.   (define-key texinfo-mode-map "\C-c{"        'texinfo-insert-braces)
  249.  
  250.   ;; bindings for inserting strings
  251.  
  252.   (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
  253.  
  254.   (define-key texinfo-mode-map "\C-c\C-cv"    'texinfo-insert-@var)
  255.   (define-key texinfo-mode-map "\C-c\C-ct"    'texinfo-insert-@table)
  256.   (define-key texinfo-mode-map "\C-c\C-cs"    'texinfo-insert-@samp)
  257.   (define-key texinfo-mode-map "\C-c\C-co"    'texinfo-insert-@noindent)
  258.   (define-key texinfo-mode-map "\C-c\C-cn"    'texinfo-insert-@node)
  259.   (define-key texinfo-mode-map "\C-c\C-ck"    'texinfo-insert-@kbd)
  260.   (define-key texinfo-mode-map "\C-c\C-ci"    'texinfo-insert-@item)
  261.   (define-key texinfo-mode-map "\C-c\C-cf"    'texinfo-insert-@file)
  262.   (define-key texinfo-mode-map "\C-c\C-cx"    'texinfo-insert-@example)
  263.   (define-key texinfo-mode-map "\C-c\C-ce"    'texinfo-insert-@end)
  264.   (define-key texinfo-mode-map "\C-c\C-cd"    'texinfo-insert-@dfn)
  265.   (define-key texinfo-mode-map "\C-c\C-cc"    'texinfo-insert-@code))
  266.  
  267.  
  268. ;;; Texinfo mode
  269.  
  270. (defvar texinfo-chapter-level-regexp 
  271.   "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
  272.   "Regular expression matching Texinfo chapter-level headings.
  273. This does not match `@node' and does not match the `@top' command.")
  274.  
  275. ;;;###autoload
  276. (defun texinfo-mode ()
  277.   "Major mode for editing Texinfo files.
  278.  
  279.   It has these extra commands:
  280. \\{texinfo-mode-map}
  281.  
  282.   These are files that are used as input for TeX to make printed manuals
  283. and also to be turned into Info files with \\[makeinfo-buffer] or
  284. the `makeinfo' program.  These files must be written in a very restricted and
  285. modified version of TeX input format.
  286.  
  287.   Editing commands are like text-mode except that the syntax table is
  288. set up so expression commands skip Texinfo bracket groups.  To see
  289. what the Info version of a region of the Texinfo file will look like,
  290. use \\[makeinfo-region], which runs `makeinfo' on the current region.
  291.  
  292.   You can show the structure of a Texinfo file with \\[texinfo-show-structure].
  293. This command shows the structure of a Texinfo file by listing the
  294. lines with the @-sign commands for @chapter, @section, and the like.
  295. These lines are displayed in another window called the *Occur* window.
  296. In that window, you can position the cursor over one of the lines and
  297. use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
  298. in the Texinfo file.
  299.  
  300.   In addition, Texinfo mode provides commands that insert various
  301. frequently used @-sign commands into the buffer.  You can use these
  302. commands to save keystrokes.  And you can insert balanced braces with
  303. \\[texinfo-insert-braces] and later use the command \\[up-list] to
  304. move forward past the closing brace.
  305.  
  306. Also, Texinfo mode provides functions for automatically creating or
  307. updating menus and node pointers.  These functions
  308.  
  309.   * insert the `Next', `Previous' and `Up' pointers of a node,
  310.   * insert or update the menu for a section, and
  311.   * create a master menu for a Texinfo source file.
  312.  
  313. Here are the functions:
  314.  
  315.     texinfo-update-node                \\[texinfo-update-node]
  316.     texinfo-every-node-update          \\[texinfo-every-node-update]
  317.     texinfo-sequential-node-update 
  318.  
  319.     texinfo-make-menu                  \\[texinfo-make-menu]
  320.     texinfo-all-menus-update           \\[texinfo-all-menus-update]
  321.     texinfo-master-menu
  322.  
  323.     texinfo-indent-menu-description (column &optional region-p)
  324.  
  325. The `texinfo-column-for-description' variable specifies the column to
  326. which menu descriptions are indented. 
  327.  
  328. Passed an argument (a prefix argument, if interactive), the
  329. `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
  330. in the region.
  331.  
  332. To use the updating commands, you must structure your Texinfo file
  333. hierarchically, such that each `@node' line, with the exception of the
  334. Top node, is accompanied by some kind of section line, such as an
  335. `@chapter' or `@section' line.
  336.  
  337. If the file has a `top' node, it must be called `top' or `Top' and
  338. be the first node in the file.
  339.  
  340. Entering Texinfo mode calls the value of text-mode-hook, and then the
  341. value of texinfo-mode-hook."
  342.   (interactive)
  343.   (text-mode)
  344.   (setq mode-name "Texinfo")
  345.   (setq major-mode 'texinfo-mode)
  346.   (use-local-map texinfo-mode-map)
  347.   (set-syntax-table texinfo-mode-syntax-table)
  348.   (make-local-variable 'page-delimiter)
  349.   (setq page-delimiter 
  350.         (concat 
  351.          "^@node [ \t]*[Tt]op\\|^@\\(" 
  352.          texinfo-chapter-level-regexp 
  353.          "\\)"))
  354.   (make-local-variable 'require-final-newline)
  355.   (setq require-final-newline t)
  356.   (make-local-variable 'indent-tabs-mode)
  357.   (setq indent-tabs-mode nil)
  358.   (make-local-variable 'paragraph-separate)
  359.   (setq paragraph-separate (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-separate))
  360.   (make-local-variable 'paragraph-start)
  361.   (setq paragraph-start (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-start))
  362.   (make-local-variable 'fill-column)
  363.   (setq fill-column 72)
  364.   (make-local-variable 'comment-start)
  365.   (setq comment-start "@c ")
  366.   (make-local-variable 'comment-start-skip)
  367.   (setq comment-start-skip "@c +")
  368.   (make-local-variable 'words-include-escapes)
  369.   (setq words-include-escapes t)
  370.   (make-local-variable 'tex-start-of-header)
  371.   (setq tex-start-of-header "%**start")
  372.   (make-local-variable 'tex-end-of-header)
  373.   (setq tex-end-of-header "%**end")
  374.   (run-hooks 'text-mode-hook 'texinfo-mode-hook))
  375.  
  376.  
  377. ;;; Insert string commands
  378.  
  379. (defconst texinfo-environment-regexp
  380.   "^@\\(f?table\\|enumerate\\|itemize\\|ifinfo\\|iftex\\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|end\\)"
  381.   "Regexp for environment-like TexInfo list commands.
  382. Subexpression 1 is what goes into the corresponding `@end' statement.")
  383.  
  384. ;; The following texinfo-insert-@end command not only inserts a SPC
  385. ;; after the @end, but tries to find out what belongs there.  It is
  386. ;; not very smart: it does not understand nested lists.
  387.  
  388. (defun texinfo-insert-@end ()
  389.   "Insert the matching `@end' for the last Texinfo command that needs one."
  390.   (interactive)
  391.   (let ((depth 1) string)
  392.     (save-excursion
  393.       (while (and (> depth 0)
  394.           (re-search-backward texinfo-environment-regexp nil t)
  395.     (if (looking-at "@end")
  396.         (setq depth (1+ depth))
  397.       (setq depth (1- depth)))))
  398.       (looking-at texinfo-environment-regexp)
  399.       (setq string
  400.         (buffer-substring (match-beginning 1)
  401.                   (match-end 1))))
  402.     (insert "@end ")
  403.     (if string (insert string "\n"))))
  404.  
  405. ;; The following insert commands accept a prefix arg N, which is the
  406. ;; number of words (actually s-exprs) that should be surrounded by
  407. ;; braces.  Thus you can first paste a variable name into a .texinfo
  408. ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
  409. ;; pasted variable name to put @var{...} *around* the variable name.
  410. ;; Operate on previous word or words with negative arg.
  411.  
  412. ;; These commands use texinfo-insert-@-with-arg
  413. (defun texinfo-insert-@-with-arg (string &optional arg)
  414.   (if arg 
  415.       (progn
  416.         (setq arg (prefix-numeric-value arg))
  417.         (if (< arg 0)
  418.             (progn
  419.               (skip-chars-backward " \t\n\r\f")
  420.               (save-excursion
  421.                 (forward-sexp arg)
  422.                 (insert "@" string "{"))
  423.               (insert "}"))
  424.           (skip-chars-forward " \t\n\r\f")
  425.           (insert "@" string "{")
  426.           (forward-sexp arg)
  427.           (insert "}")))
  428.     (insert "@" string "{}")
  429.     (backward-char)))
  430.  
  431. (defun texinfo-insert-braces ()
  432.   "Make a pair of braces and be poised to type inside of them.
  433. Use \\[up-list] to move forward out of the braces."
  434.   (interactive)
  435.   (insert "{}")
  436.   (backward-char))
  437.  
  438. (defun texinfo-insert-@code (&optional arg)
  439.   "Insert a `@code{...}' command in a Texinfo buffer.
  440. A numeric argument says how many words the braces should surround.
  441. The default is not to surround any existing words with the braces."
  442.   (interactive "P")
  443.   (texinfo-insert-@-with-arg "code" arg))
  444.  
  445. (defun texinfo-insert-@dfn (&optional arg)
  446.   "Insert a `@dfn{...}' command in a Texinfo buffer.
  447. A numeric argument says how many words the braces should surround.
  448. The default is not to surround any existing words with the braces."
  449.   (interactive "P")
  450.   (texinfo-insert-@-with-arg "dfn" arg))
  451.  
  452. (defun texinfo-insert-@example ()
  453.   "Insert the string `@example' in a Texinfo buffer."
  454.   (interactive)
  455.   (insert "@example\n"))
  456.  
  457. (defun texinfo-insert-@file (&optional arg)
  458.   "Insert a `@file{...}' command in a Texinfo buffer.
  459. A numeric argument says how many words the braces should surround.
  460. The default is not to surround any existing words with the braces."
  461.   (interactive "P")
  462.   (texinfo-insert-@-with-arg "file" arg))
  463.  
  464. (defun texinfo-insert-@item ()
  465.   "Insert the string `@item' in a Texinfo buffer."
  466.   (interactive)
  467.   (insert "@item")
  468.   (newline))
  469.  
  470. (defun texinfo-insert-@kbd (&optional arg)
  471.   "Insert a `@kbd{...}' command in a Texinfo buffer.
  472. A numeric argument says how many words the braces should surround.
  473. The default is not to surround any existing words with the braces."
  474.   (interactive "P")
  475.   (texinfo-insert-@-with-arg "kbd" arg))
  476.  
  477. (defun texinfo-insert-@node ()
  478.   "Insert the string `@node' in a Texinfo buffer.
  479. This also inserts on the following line a comment indicating
  480. the order of arguments to @node."
  481.   (interactive)
  482.   (insert "@node \n@comment  node-name,  next,  previous,  up")
  483.   (forward-line -1)
  484.   (forward-char 6))
  485.  
  486. (defun texinfo-insert-@noindent ()
  487.   "Insert the string `@noindent' in a Texinfo buffer."
  488.   (interactive)
  489.   (insert "@noindent\n"))
  490.  
  491. (defun texinfo-insert-@samp (&optional arg)
  492.   "Insert a `@samp{...}' command in a Texinfo buffer.
  493. A numeric argument says how many words the braces should surround.
  494. The default is not to surround any existing words with the braces."
  495.   (interactive "P")
  496.   (texinfo-insert-@-with-arg "samp" arg))
  497.  
  498. (defun texinfo-insert-@table (&optional arg)
  499.   "Insert the string `@table' in a Texinfo buffer."
  500.   (interactive "P")
  501.   (insert "@table "))
  502.  
  503. (defun texinfo-insert-@var (&optional arg)
  504.   "Insert a `@var{}' command in a Texinfo buffer.
  505. A numeric argument says how many words the braces should surround.
  506. The default is not to surround any existing words with the braces."
  507.   (interactive "P")
  508.   (texinfo-insert-@-with-arg "var" arg))
  509.  
  510. ;;; Texinfo file structure
  511.  
  512. (defun texinfo-show-structure (&optional nodes-too) 
  513.   "Show the structure of a Texinfo file.
  514. List the lines in the file that begin with the @-sign commands for
  515. @chapter, @section, and the like.
  516.  
  517. With optional argument (prefix if interactive), list both the lines
  518. with @-sign commands for @chapter, @section, and the like, and list
  519. @node lines.
  520.  
  521. Lines with structuring commands beginning in them are displayed in
  522. another buffer named `*Occur*'.  In that buffer, you can move point to
  523. one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence], 
  524. to jump to the corresponding spot in the Texinfo source file."
  525.  
  526.   (interactive "P")
  527.   (require 'texnfo-upd)
  528.   (save-excursion 
  529.     (goto-char (point-min))
  530.     (if nodes-too
  531.         (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
  532.       (occur texinfo-section-types-regexp)))
  533.   (pop-to-buffer "*Occur*")
  534.   (goto-char (point-min))
  535.   (flush-lines "-----")
  536.   ;; Now format the "*Occur*" buffer to show the structure.
  537.   ;; Thanks to ceder@signum.se (Per Cederqvist)
  538.   (goto-char (point-max))
  539.   (let ((margin 5))
  540.     (while (re-search-backward "^ *[0-9]*:" nil 0)
  541.       (re-search-forward ":")
  542.       (setq margin
  543.             (cond
  544.              ((looking-at (concat "@" texinfo-chapter-level-regexp)) 5)
  545.              ;; ((looking-at "@chapter ") 5)
  546.              ;; ((looking-at "@unnumbered ") 5)
  547.              ;; ((looking-at "@appendix ") 5)
  548.              ;; ((looking-at "@majorheading ") 5)
  549.              ;; ((looking-at "@chapheading ") 5)
  550.  
  551.              ((looking-at (concat "@" texinfo-section-level-regexp)) 9)
  552.              ;; ((looking-at "@section ") 9)
  553.              ;; ((looking-at "@unnumberedsec ") 9)
  554.              ;; ((looking-at "@appendixsec ") 9)
  555.              ;; ((looking-at "@heading ") 9)
  556.  
  557.              ((looking-at (concat "@" texinfo-subsection-level-regexp)) 13)
  558.              ;; ((looking-at "@subsection ") 13)
  559.              ;; ((looking-at "@unnumberedsubsec ") 13)
  560.              ;; ((looking-at "@appendixsubsec ") 13)
  561.              ;; ((looking-at "@subheading ") 13)
  562.  
  563.              ((looking-at (concat "@" texinfo-subsubsection-level-regexp)) 17)
  564.              ;; ((looking-at "@subsubsection ") 17)
  565.              ;; ((looking-at "@unnumberedsubsubsec ") 17)
  566.              ;; ((looking-at "@appendixsubsubsec ") 17)
  567.              ;; ((looking-at "@subsubheading ") 17)
  568.              (t margin)))
  569.       (indent-to-column margin)
  570.       (beginning-of-line))))
  571.  
  572. ;;; The  tex  and  print  function definitions:
  573.  
  574. (defvar texinfo-tex-command "texi2dvi"
  575.   "*Command used by `texinfo-tex-region' to run TeX on a region.")
  576.  
  577. (defvar texinfo-texindex-command "texindex"
  578.   "*Command used by `texinfo-texindex' to sort unsorted index files.")
  579.  
  580. (defvar texinfo-delete-from-print-queue-command "lprm"
  581.   "*Command string used to delete a job from the line printer queue.
  582. Command is used by \\[texinfo-delete-from-print-queue] based on
  583. number provided by a previous \\[tex-show-print-queue]
  584. command.")
  585.  
  586. (defvar texinfo-tex-trailer "@bye"
  587.   "String appended after a region sent to TeX by `texinfo-tex-region'.")
  588.  
  589. (defun texinfo-tex-region (beg end)
  590.   "Run TeX on the current region.
  591. This works by writing a temporary file (`tex-zap-file') in the directory
  592. that is the value of `tex-directory', then running TeX on that file.
  593.  
  594. The first line of the buffer is copied to the
  595. temporary file; and if the buffer has a header, it is written to the
  596. temporary file before the region itself.  The buffer's header is all lines
  597. between the strings defined by `tex-start-of-header' and `tex-end-of-header'
  598. inclusive.  The header must start in the first 100 lines.
  599.  
  600. The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
  601.   (interactive "r")
  602.   (require 'tex-mode)
  603.   (if (get-buffer "*tex-shell*")
  604.       (tex-kill-job)
  605.     (tex-start-shell))
  606.   (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
  607.   (let ((tex-out-file (concat tex-zap-file ".tex"))
  608.     (temp-buffer (get-buffer-create " tex-Output-Buffer"))
  609.     (zap-directory
  610.          (file-name-as-directory (expand-file-name tex-directory))))
  611.     (save-excursion
  612.       (save-restriction
  613.     (widen)
  614.     (goto-char (point-min))
  615.     (forward-line 100)
  616.     (let ((search-end (point))
  617.           (hbeg (point-min)) (hend (point-min))
  618.           (default-directory zap-directory))
  619.       (goto-char (point-min))
  620.           
  621.           ;; Copy first line, the `\input texinfo' line, to temp file
  622.       (write-region (point) 
  623.                         (save-excursion (end-of-line) (point))
  624.                         tex-out-file nil nil)
  625.           
  626.           ;; Don't copy first line twice if region includes it.
  627.           (forward-line 1)
  628.           (if (< beg (point)) (setq beg (point)))
  629.           
  630.           ;; Initialize the temp file with either the header or nothing
  631.           (if (search-forward tex-start-of-header search-end t)
  632.               (progn
  633.                 (beginning-of-line)
  634.                 (setq hbeg (point))    ; Mark beginning of header.
  635.                 (if (search-forward tex-end-of-header nil t)
  636.                     (progn (beginning-of-line)
  637.                            (setq hend (point)))    ; Mark end of header.
  638.                   (setq hbeg (point-min))))) ; Else no header.
  639.           
  640.           ;; Copy  header  to temp file.
  641.           (write-region (min hbeg beg) hend tex-out-file t nil)
  642.           
  643.           ;; Copy  region  to temp file.
  644.           (write-region (max beg hend) end tex-out-file t nil))
  645.         
  646.         ;; This is  a kludge to insert the tex-trailer into the tex-out-file.
  647.         ;;  We have to create a special buffer in which to insert
  648.         ;;  the tex-trailer first because there is no function with
  649.         ;;  which to append a literal string directly to a file.
  650.         (let ((local-tex-trailer texinfo-tex-trailer))
  651.           (set-buffer temp-buffer)
  652.           (erase-buffer)
  653.           ;; make sure trailer isn't hidden by a comment
  654.           (insert-string "\n")
  655.           (if local-tex-trailer (insert-string local-tex-trailer))
  656.           (tex-set-buffer-directory temp-buffer zap-directory)
  657.           (write-region (point-min) (point-max) tex-out-file t nil))
  658.  
  659. ;;; The following is sufficient in Emacs 19.
  660. ;;;    (write-region (concat "\n" texinfo-tex-trailer) nil
  661. ;;;              tex-out-file t nil)
  662.     ))
  663.     
  664.     (tex-set-buffer-directory "*tex-shell*" zap-directory)
  665.     (send-string "tex-shell" (concat tex-shell-cd-command " "
  666.                                      zap-directory "\n"))
  667.     (send-string "tex-shell" (concat texinfo-tex-command " "
  668.                                      tex-out-file "\n")))
  669.   (tex-recenter-output-buffer 0))
  670.  
  671. (defun texinfo-tex-buffer ()
  672.   "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
  673.   (interactive)
  674.  
  675.   ;; Make sure TeX shell is running.
  676.   (if (get-buffer "*tex-shell*")
  677.       (quit-process (get-process "tex-shell") t)
  678.     (tex-start-shell))
  679.  
  680.   (cond ((null buffer-file-name)
  681.          (error "Buffer not visiting any file!"))
  682.         ((buffer-modified-p)
  683.          (error "Buffer has been modified since last saved!")))
  684.  
  685.   (setq tex-zap-file buffer-file-name)
  686.  
  687.   (send-string "tex-shell"
  688.            (concat tex-shell-cd-command 
  689.                " " (file-name-directory tex-zap-file) "\n"))
  690.  
  691.   (send-string "tex-shell"
  692.            (concat texinfo-tex-command " " tex-zap-file "\n"))
  693.  
  694.   (tex-recenter-output-buffer 0))
  695.  
  696. (defun texinfo-texindex ()
  697.   "Run `texindex' on unsorted index files.
  698. The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  699. This runs the shell command defined by `texinfo-texindex-command'."
  700.   (interactive)
  701.   (require 'tex-mode)
  702.   (send-string "tex-shell"
  703.            (concat texinfo-texindex-command
  704.                        " " tex-zap-file ".??" "\n"))
  705.   (tex-recenter-output-buffer nil))
  706.  
  707. (defun texinfo-tex-print ()
  708.   "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  709. This runs the shell command defined by `tex-dvi-print-command'."
  710.   (interactive)
  711.   (require 'tex-mode)
  712.   (send-string "tex-shell"
  713.            (concat tex-dvi-print-command
  714.                        " " tex-zap-file ".dvi" "\n"))
  715.   (tex-recenter-output-buffer nil))
  716.  
  717. (defun texinfo-quit-job ()
  718.   "Quit currently running TeX job, by sending an `x' to it."
  719.   (interactive)
  720.   (if (not (get-process "tex-shell"))
  721.       (error "No TeX shell running"))
  722.   (save-excursion
  723.     (set-buffer (get-buffer "*tex-shell*"))
  724.     (goto-char (point-max))
  725.     (insert "x")
  726.     (shell-send-input)))
  727.  
  728. (defun texinfo-delete-from-print-queue (job-number)
  729.   "Delete job from the line printer spooling queue.
  730. You are prompted for the job number (use a number shown by a previous
  731. \\[texinfo-show-tex-print-queue] command)."
  732.   (interactive "nPrinter job number for deletion: ")
  733.   (if (tex-shell-running)
  734.       (tex-kill-job)
  735.     (tex-start-shell))
  736.   (send-string "tex-shell"
  737.                (concat 
  738.                 texinfo-delete-from-print-queue-command
  739.                 " "
  740.                 job-number"\n"))
  741.   (tex-recenter-output-buffer nil))
  742.  
  743. (provide 'texinfo)
  744.  
  745. ;;; texinfo.el ends here
  746.